package com.kuzan.autocloud.common.model.organization;

import com.kuzan.autocloud.common.model.Base;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * <p>Description: 角色组</p>
 *
 * @author kuzank
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "sys_organization_rolegroup_item")
public class RoleItem extends Base {

    @Column(length = 32)
    private String rolegroupid;
    @Column(length = 12)
    private String scope;
    @Column(length = 32)
    private String organization;
    @Column(length = 32)
    private String person;

    public static RoleItem ofOrganization(String belong, String organization, String id) {
        return of(belong, RolePermissionScope.Orgunit.value(), organization, null, id);
    }

    public static RoleItem ofAccount(String belong, String person, String id) {
        return of(belong, RolePermissionScope.Person.value(), null, person, id);
    }

    public static RoleItem of(String belong, String scope, String organization, String person, String id) {
        RoleItem o = new RoleItem();
        o.setId(id);
        o.setRolegroupid(belong);
        o.setScope(scope);
        o.setOrganization(organization);
        o.setPerson(person);
        return o;
    }

    /**
     * 角色权限
     */
    public enum RolePermissionScope {
        pid("rps"),

        Orgunit("rps_origunit"),
        Person("rps_person");

        private String name;

        RolePermissionScope(String name) {
            this.name = name;
        }

        public String value() {
            return name;
        }

        public String getName() {
            return name;
        }

    }
}
